/*
 * SPI.c
 *
 * Created: 1/18/2013 1:50:37 PM
 *  Author: Alexander
 */ 
#include "SPI.h"

void InitSPI(void)
{
	DDRB = (1<<PB1)|(1<<PB2);	 // Set MOSI and SCK as output
	SPCR = ( (1<<SPE)|(1<<MSTR) |(1<<CPHA)|(1<<CPOL)|(1<<SPR0));	// Enable SPI, Master, set clock rate fck/16
}

void WriteByteSPI(uint8_t byte)
{	
	SPDR = byte;					//Load byte to Data register
	while(!(SPSR & (1<<SPIF))); 	// Wait for transmission complete
}

uint8_t ReadByteSPI(uint8_t addr)
{
	SPDR = addr;					//Load byte to Data register
	while(!(SPSR & (1<<SPIF)));
	return SPDR;
}